/*
 * <p>Copyright ®Alyce_WX版权所有。</p>
 * 类名:DictDaoImpl
 * 创建人:alyce_wx
 * 创建时间:2017-03-30
 */

package com.wx.demo.wcd.infrastructure.dao.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import com.wx.demo.wcd.domain.pk.DictPK;
import com.wx.demo.wcd.domain.po.DictPO;
import com.wx.demo.wcd.domain.qo.DictQO;
import com.wx.demo.wcd.infrastructure.dao.DictDao;
import com.yjhl.framework.dao.AbstractDao;

/**
 * DictDAO implement
 *
 * @author alyce_wx
 * @see com.yjhl.framework.dao.AbstractDao
 * @see com.wx.demo.wcd.infrastructure.dao.DictDao;
 * @since 1.8
 * @version 1.0.0
 */

@Repository("dictDao")
public class DictDaoImpl extends AbstractDao<DictPO, DictQO, DictPK> implements
		DictDao {
	/**
	 * spring SQL session
	 */
	@Resource
	private SqlSessionTemplate wcdSqlSessionTemplate;

	/**
	 * Get SQL session。 Get SQL session since spring auto wired.
	 *
	 * @return SQL session
	 * @see com.yjhl.framework.dao.AbstractDAO#getSqlSessionTemplate()
	 * @since 1.8
	 * @version 1.0.0
	 */
	@Override
	protected SqlSessionTemplate getSqlSessionTemplate() {
		return wcdSqlSessionTemplate;
	}

	/**
	 * 获取mybatis的命名空间。
	 *
	 * @return MyBatis的命名空间.
	 * @see com.yjhl.framework.dao.AbstractDAO#getNamespace()
	 * @since 1.8
	 * @version 1.0.0
	 */
	@Override
	protected String getNamespace() {
		return "wcddictDAO";
	}

	/**
	 * 获取不带"-"的UUID。
	 *
	 * @return 不带"-"的UUID.
	 * @see com.yjhl.framework.dao.AbstractDao#getSequence()
	 * @since 1.8
	 * @version 1.0.0
	 */
	@Override
	public String getSequence() {
		return getSequenceUUID("dict");

	}

	/**
	 * 插入单条数据。 如果entity的属性值为null或空，该属性对应的列将不会被插入。
	 *
	 * @param entity
	 *            插入的内容.
	 * @return 插入记录条数
	 * @see com.yjhl.framework.dao.AbstractDao#insert(com.yjhl.framework.domain.po.PO)
	 * @since 1.8
	 * @version 1.0.0
	 */
	@Override
	public int insert(DictPO entity) {
		if (null == entity.getDictId() || "".equals(entity.getDictId())) {
			entity.setDictId(getSequenceUUID("dict"));
		}

		return super.insert(entity);
	}

	/**
	 * @see DictDao#getByPk(String)
	 */
	@Override
	public DictPO getByPk(String dictId) {
		DictPK entityPK = new DictPK(dictId);

		return super.getByPk(entityPK);
	}

	/**
	 * @see DictDao#updateMapByPk(Map, String)
	 */
	@Override
	public int updateMapByPk(Map<String, Object> entity, String dictId) {
		DictPK entityPK = new DictPK(dictId);

		return super.updateMapByPk(entity, entityPK);
	}

	/**
	 * @see DictDao#deleteByPk(String)
	 */
	@Override
	public int deleteByPk(String dictId) {
		DictPK entityPK = new DictPK(dictId);

		return super.deleteByPk(entityPK);
	}

}
